package com.thingtrack.konekti.view.web.form;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import com.thingtrack.konekti.domain.MenuCommandResource;
import com.thingtrack.konekti.service.api.MenuCommandResourceService;
import com.thingtrack.konekti.view.addon.data.BindingSource;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Select;
import com.vaadin.ui.TextField;
@SuppressWarnings("serial")
public class PermissionViewForm extends CustomComponent {
@AutoGenerated
private AbsoluteLayout mainLayout;
@AutoGenerated
private ComboBox menuCommandResourceField;
@AutoGenerated
private TextField descriptionField;
@AutoGenerated
private TextField codeField;
@AutoGenerated
private TextField commentField;
@AutoGenerated
private CheckBox activeField;
/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
private MenuCommandResourceService menuCommandResourceService;
// command datasource
private BeanItemContainer<MenuCommandResource> bcMenuCommandResource = new BindingSource<MenuCommandResource>(MenuCommandResource.class);
/**
* The constructor should first build the main layout, set the composition
* root and then do any custom initialization.
*
* The constructor will not be automatically regenerated by the visual
* editor.
* @throws Exception
* @throws IllegalArgumentException
*/
public PermissionViewForm() throws IllegalArgumentException, Exception {
buildMainLayout();
setCompositionRoot(mainLayout);
// TODO add user code here
initComponents();
menuCommandResourceField.setNullSelectionAllowed(false);
menuCommandResourceField.setItemCaptionMode(Select.ITEM_CAPTION_MODE_PROPERTY);
menuCommandResourceField.setItemCaptionPropertyId("caption");
// get form services from OSGi Service Registry
getServices();
loadData();
}
private void initComponents() {
codeField.setNullRepresentation("");
descriptionField.setNullRepresentation("");
commentField.setNullRepresentation("");
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void getServices() {
try {
BundleContext bundleContext = FrameworkUtil.getBundle(PermissionViewForm.class).getBundleContext();
ServiceReference menuCommandResourceServiceReference = bundleContext.getServiceReference(MenuCommandResourceService.class.getName());
menuCommandResourceService = MenuCommandResourceService.class.cast(bundleContext.getService(menuCommandResourceServiceReference));
}
catch (Exception e) {
e.getMessage();
}
}
private void loadData() throws IllegalArgumentException, Exception {
bcMenuCommandResource.removeAllItems();
bcMenuCommandResource.addAll(menuCommandResourceService.getAll());
menuCommandResourceField.setContainerDataSource(bcMenuCommandResource);
}
@AutoGenerated
private AbsoluteLayout buildMainLayout() {
// common part: create layout
mainLayout = new AbsoluteLayout();
mainLayout.setImmediate(false);
mainLayout.setWidth("580px");
mainLayout.setHeight("280px");
mainLayout.setMargin(true);
// top-level component properties
setWidth("580px");
setHeight("280px");
// activeField
activeField = new CheckBox();
activeField.setCaption("Activo");
activeField.setImmediate(false);
activeField.setWidth("-1px");
activeField.setHeight("-1px");
activeField.setRequired(true);
mainLayout.addComponent(activeField, "top:14.0px;left:507.0px;");
// commentField
commentField = new TextField();
commentField.setCaption("Comentario");
commentField.setImmediate(true);
commentField.setWidth("540px");
commentField.setHeight("160px");
mainLayout.addComponent(commentField, "top:100.0px;left:20.0px;");
// codeField
codeField = new TextField();
codeField.setCaption("Código");
codeField.setImmediate(false);
codeField.setWidth("160px");
codeField.setHeight("-1px");
codeField.setRequired(true);
mainLayout.addComponent(codeField, "top:17.0px;left:20.0px;");
// descriptionField
descriptionField = new TextField();
descriptionField.setCaption("Descripción");
descriptionField.setImmediate(false);
descriptionField.setWidth("541px");
descriptionField.setHeight("-1px");
descriptionField.setRequired(true);
mainLayout.addComponent(descriptionField, "top:56.0px;left:20.0px;");
// menuCommandResourceField
menuCommandResourceField = new ComboBox();
menuCommandResourceField.setCaption("Módulo:");
menuCommandResourceField.setImmediate(true);
menuCommandResourceField.setWidth("280px");
menuCommandResourceField.setHeight("-1px");
menuCommandResourceField.setRequired(true);
mainLayout.addComponent(menuCommandResourceField,
"top:17.0px;left:200.0px;");
return mainLayout;
}
}